package main.Q101_200;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Q181_190 {
    public static void main(String[] args) {
        System.out.println("Question181：超过经理收入的员工(SQL)");
        System.out.println("Question182：查找重复的电子邮箱");
        System.out.println("Question183：从不订购的客户");
        System.out.println("Question184：部门工资最高的员工");
        System.out.println("Question185：");
        System.out.println("Question186：");
        System.out.println("Question187：重复的DNA序列");
        System.out.println("Question188：");
        System.out.println("Question189：轮转数组");
        System.out.println("Question190：颠倒二进制位");
    }
}

class Question181 {
    {
        System.out.println("select name Employee\n" +
                "from Employee b\n" +
                "where salary>(select salary from Employee where id=b.managerId);");
    }
}

class Question182 {
    {
        System.out.println("select Email from\n" +
                "(\n" +
                "  select Email, count(Email) as num\n" +
                "  from Person\n" +
                "  group by Email\n" +
                ") as statistic\n" +
                "where num > 1;");
    }
}

class Question183 {
    {
        System.out.println("select Name Customers\n" +
                "from Customers\n" +
                "where Id not in (select distinct CustomerId from Orders);");
    }
}

class Question184 {
    {
        System.out.println("select b.name Department,a.name Employee,a.salary Salary\n" +
                "from Employee a join Department b\n" +
                "on (a.departmentId=b.id)\n" +
                "where\n" +
                "(a.DepartmentId,salary) in(\n" +
                "    select DepartmentId,max(salary) \n" +
                "    from Employee\n" +
                "    Group by DepartmentId\n" +
                ");");
    }
}

class Question187 {
    public List<String> findRepeatedDnaSequences(String s) {
        Map<String, Integer> map = new HashMap<>();
        List<String> ans = new ArrayList<>();
        int a = 0, b = 10, n = s.length();
        if (n <= 10) return ans;
        while (b <= n) {
            String sub = s.substring(a, b);
            map.put(sub, map.getOrDefault(sub, 0) + 1);
            a++;
            b++;
        }
        for (String sub : map.keySet()) {
            if (map.get(sub) > 1) ans.add(sub);
        }
        return ans;
    }
}

class Question189 {
//    public void rotate(int[] nums, int k) {
//        int length= nums.length;
//        k=k%length;
//        List<Integer> list=new ArrayList<>();
//        for (int i=length-k;i<length;i++) list.add(nums[i]);
//        for (int i=length-k-1;i>=0;i--) nums[i+k]=nums[i];
//        for (int i=0;i<list.size();i++) nums[i]=list.get(i);
//    }

    public void rotate(int[] nums, int k) {
        k = nums.length - k % nums.length;
        if (k != 0) {
            int[] temp = new int[k];
            for (int i = 0; i < k; i++) {// 暂存
                temp[i] = nums[i];
            }
            for (int i = k; i < nums.length; i++) {// 前移
                nums[i - k] = nums[i];
            }
            for (int i = 0; i < k; i++) {// 覆盖
                nums[i + nums.length - k] = temp[i];
            }
        }
    }
}

class Question190 {
    public int reverseBits(int n) {
        int result = 0;
        for (int i = 0; i < 32 && n != 0; i++) {
            result |= (n & 1) << (31 - i);
            n >>>= 1;
        }
        return result;
    }
}